﻿using System;
using System.Drawing;
using Book_Shop.BLL;
using Book_Shop.DAL.DAO;

namespace Book_Shop.UI
{
    public partial class OrderSheetUI : System.Web.UI.Page
    {
        private OrderManager orderManager = new OrderManager();
        private SalesManager salesManager = new SalesManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                OrderSheet orderSheet = (OrderSheet) Session["CurrentOrderSheet"];
                RenderOrderSheet(orderSheet);
            }
        }

        private void RenderOrderSheet(OrderSheet orderSheet)
        {
            shopAddressLabel.Text = orderSheet.Shop.Location;
            shopTitleLabel.Text = orderSheet.Shop.Title;
            readerNameTextBox.Text = orderSheet.Reader.FullName;
            readerEmailTextBox.Text = orderSheet.Reader.Email;
            readerAddressTextBox.Text = orderSheet.Reader.Address;
            bookListGridView.DataSource = orderSheet.Books;
            subTotalLabel.Text = orderSheet.TotalPrice.ToString();
            orderDateLabel.Text = orderSheet.DateOfOrder.ToString();
            bookListGridView.DataBind();
        }

        protected void checkOutButton_Click(object sender, EventArgs e)
        {
            OrderSheet orderSheet = (OrderSheet)Session["CurrentOrderSheet"];
            orderSheet.Status = statusDropDown.Text;
            try
            {
                string message = salesManager.CheckOut(orderSheet);
                messageLabel.ForeColor = Color.Green;
                messageLabel.Text = message;

            }
            catch (Exception exception)
            {

                messageLabel.ForeColor = Color.Red;
                messageLabel.Text = exception.Message;
            }
           
        }
    }

   
}